/**
 * 会员登录
 */
function userLogin()
{
	var frm 	= document.forms['formLogin'];
	var username= frm.elements['username'].value;
	var password = frm.elements['password'].value;
	var msg = '';
	
	if(username.length == 0)
	{
		msg += username_empty + '\n';
	}
	
	if(password.length == 0)
	{
		msg += password_empty + '\n';
	}
	
	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}


/*
	用户提交注册请求，进行校验
*/

function register()
{
	var frm = document.forms['formUser'];
	var username = Utils.trim(frm.elements['username'].value);
	var email = frm.elements['email'].value;
	var password = Utils.trim(frm.elements['password'].value);
	var confirm_password = Utils.trim(frm.elements['confirm_password'].value);
	var checked_agreement = frm.elements['agreement'].checked;
	var msn = frm.elements['extend_field1'] ? Utils.trim(frm.elements['extend_field1'].value): '';
	var qq = frm.elements['extend_field2'] ? Utils.trim(frm.elements['extend_field2'].value) : '';
	var office_phone = frm.elements['extend_field3'] ? Utils.trim(frm.elements['extend_field3'].value) : '';
	var home_phone = frm.elements['extend_field4'] ? Utils.trim(frm.elements['extend_field4'].value) : '';
	var mobile_phone = frm.elements['extend_field5'] ? Utils.trim(frm.elements['extend_field5'].value) : '';
	var passwd_answer = frm.elements['passwd_answer'] ? Utils.trim(frm.elements['passwd_answer'].value) : '';
	var sel_question = frm.elements['sel_question'] ? Utils.trim(frm.elements['sel_question'].value) : '';
	
	var msg = "";
	if(username.length == 0)
	{
		msg += username_empty + '\n';
	}
	else if(username.match(/^\s*$|^c:\\con\\con$|[%,\'\*\"\s\t\<\>\&\\]/))
	{
		msg += username_invalid + '\n';
	}
	else if(username.length <3)
	{
		
	}
	
	if(email.length == 0)
	{
		msg += email_empty + '\n';
	}
	else
	{
		if(!(Utils.isEmail(email)))
		{
			msg += email_invalid + '\n';
		}
	}
	
	if(password.length == 0)
	{
		msg += password_empty + '\n';
	}
	else if(password.length < 6)
	{
		msg += password_shorter + '\n';
	}
	
	if(/ /.test(password) ==  true)
	{
		msg += passwd_blank + '\n';
	}
	if(confirm_password != password)
	{
		msg += confirm_password_invalid + '\n';
	}
	if(checked_agreement != true)
	{
		msg += agreement + '\n'
	}
	if(msn.length> 0 && (!Utils.isEmail(msn)))
	{
		msg +=msn_invalid + '\n';
	}
	
	if(qq.length > 0 && (!utils.isNumber(qq)))
	{
		msg += qq_invalid + '\n';
	}
	
	if(office_phone.length > 0)
	{
		var reg = /^[\d|\-|\s]+S/;
		if(!reg.test(office_phone))
		{
			msg += office_phone_invalid + '\n';
		}
	}
	
	if(home_phone.length>0)
	{
		var reg=/^[\d|\-|\s] + $/;
		
		if(!reg.test(home_phone))
		{
			msg += mobile_phone_invalid + '\n';
		}
	}
	
	if(mobile_phone.length>0)
	{
		var reg=/^[\d|\-|\s]+$/;
		if(!reg.test(mobile_phone))
		{
			msg += mobile_phone_invalid + '\n';
		}
	}
	
	if(passwd_answer.length>0 && sel_question == 0 || document.getElementById('passwd_question') && passwd_answer.length == 0)
	{
		msg += no_select_question + '\n';
	}
	
	for(i=4;i<frm.elements.length -4;i++)
	{
		needinput = document.getElementById(frm.elements[i].name + 'i') ? document.getElmentbyId(frm.elements[i].name + 'i') : '';
		if(needinput !='' && frm.elements[i].value.length == 0)
		{
			msg += '- ' + needinput.innerHTML + msg_blank + '\n';
		}	
	}
	
	if(msg.length > 0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}
